--
-- Author: yawei.zhu
-- Date: 2018-08-25 13:44:20
--
-- PvpChampionBookRender
--
local IconRender = require("app.widget.renders.IconRender")

local ClassRef = app.mvc.createRenderClass(...)
local awardTypeDescs = { L("champion_award5"), L("champion_award6"), L("champion_award7"), L("champion_award8"), L("champion_award9"), L("throne_reward32"), L("throne_reward64")}

--data =
function ClassRef.createWithData(data, node)
    local sprite = ClassRef.extend(node or cc.CSLoader:createNode(Res.PvpChampionBookSubNode))
    if node == nil then
        ccui.Helper:doLayout(sprite)
    end
    sprite:init(data)
    return sprite
end
function ClassRef.create(node)
    return ClassRef.createWithData(nil, node)
end

--
function ClassRef:init(data)
    self.super.init(self, data)
    self:setContentSize(self._ui.Panel:getContentSize())

    self:refresh()
end

-- 冠军、亚军、4强、8强、16强
function ClassRef:refresh()
    if not self._data then return end

    local arrDatas = string.split(self._data, "|")
    local awardType = tonumber(arrDatas[1])
    local dropId = tonumber(arrDatas[2])

    if awardType == 4 then awardType = 3 end
    if awardType == 8 then awardType = 4 end
    if awardType == 16 then awardType = 5 end
    if awardType == 32 then awardType = 6 end
    if awardType == 64 then awardType = 7 end
    self._ui.tlt:setString(awardTypeDescs[awardType])
    for i = 1, 4 do
        self._ui["icon_"..i]:setVisible(false)
    end

    local itemDatas = UD:parseDropToBagItem(dropId)
    for i, itemData in ipairs(itemDatas) do
        if i > 4 then break end
        self._ui["icon_"..i]:setVisible(true)
        local render = IconRender.create(self._ui["icon_"..i])
        render:setData(itemData)
        render:setTipEnable(true)
    end

    local path = Res.ThroneBgPath .. "team_trophy_icon_3.png"
    if awardType <= 2 then
        path = Res.ThroneBgPath .. "team_trophy_icon_".. awardType .. ".png"
    end
    self._ui.img:loadTexture(path)
end

function ClassRef:onBtnClick(cb)
    self._onClick = cb
end

return ClassRef
